package com.pan.kang.flow.execute;

import com.pan.kang.dto.CreateOrderDto;
import com.pan.kang.constant.OrderType;
import com.yomahub.liteflow.core.FlowExecutor;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Component
public class CreateOrderExecute implements CommandLineRunner {

    @Resource
    private FlowExecutor flowExecutor;

    @Override
    public void run(String... args) throws Exception {
        // 模拟前端参数
        CreateOrderDto createOrderDto = new CreateOrderDto();
        createOrderDto.setOrderType(OrderType.NORMAL.getValue());
        createOrderDto.setUserId("1");
        List<CreateOrderDto.Goods> goodsList = new ArrayList<>();
        createOrderDto.setGoodsList(goodsList);
        CreateOrderDto.Goods goods = new CreateOrderDto.Goods();
        goodsList.add(goods);
        goods.setSkuId("1");
        goods.setNum(999);
        goods.setGoodId("1");
        // 流程执行
        flowExecutor.execute2Resp("createOrderChain", "订单创建流程", createOrderDto);
    }
}
